import { Request, Response } from "express";
import { NextFunction } from "express-serve-static-core";
const express = require("express");
const router = express.Router();

import r from "../r";

router.get("/selectAssets", function(
  req: Request,
  res: Response,
  next: NextFunction
) {
  const data = [
    {
      coin: "BTC",
      amount: "0.00002552",
      ava: "0.00000000",
      frozen: "0.00002551",
      id: "abc"
    },
    {
      coin: "BTC",
      amount: "0.00002552",
      ava: "0.00002551",
      frozen: "0.00002551",
      id: "abc"
    },
    {
      coin: "BTC",
      amount: "0.00002552",
      ava: "0.00002551",
      frozen: "0.00002551",
      id: "abc"
    },
    {
      coin: "BTC",
      amount: "0.00002552",
      ava: "0.00002552",
      frozen: "0.00002551",
      id: "abc"
    },
    {
      coin: "BTC",
      amount: "0.00002552",
      ava: "0.00002551",
      frozen: "0.00002551",
      id: "abc"
    },
    {
      coin: "BTC",
      amount: "0.00002552",
      ava: "0.00002551",
      frozen: "0.00002551",
      id: "abc"
    },
    {
      coin: "BTC",
      amount: "0.00002552",
      ava: "0.00002552",
      frozen: "0.00002551",
      id: "abc"
    },
    {
      coin: "BTC",
      amount: "0.00002552",
      ava: "0.00002551",
      frozen: "0.00002551",
      id: "abc"
    },
    {
      coin: "BTC",
      amount: "0.00002552",
      ava: "0.00002551",
      frozen: "0.00002551",
      id: "abc"
    }
  ]
    .filter(d => {
      return d.coin.toLowerCase().indexOf(req.query.search.toLowerCase()) > -1;
    })
    .filter(d => {
      if (req.query.hideSmall === "true") {
        return Number(d.ava) > 0;
      }
      return true;
    });
  res.json({
    code: 200,
    data,
    msg: "success"
  });
});

router.get("/findAssets", function(
  req: Request,
  res: Response,
  next: NextFunction
) {
  const { coin } = req.query;
  res.json({
    code: 200,
    data: {
      coin,
      total: "0.00002551",
      ava: "0.00002551",
      point: 5,
      frozen: "0.00000000",
      feeRatio: "0",
      baseFee: "0.001",
      withdraw: {
        addressLists: [
          {
            coin,
            remark: "sdkljflskfs",
            address: "sldkjflksjflksjdf"
          },
          {
            coin,
            remark: "sdfsaf",
            address: "23423423"
          }
        ],
        min: "0.00011",
        max: "0.1"
      }
    },
    msg: "success"
  });
});

router.get("/selectActiveHistory", function(
  req: Request,
  res: Response,
  next: NextFunction
) {
  res.json({
    code: 200,
    data: [
      {
        coin: "BTC",
        amount: "0.00002552",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        txid:
          "c59bc457c8ec14ed8aa09a4c27915256c96e19e17eb0299677112665a2cc7768",
        ago: 1542858853,
        now: 1542860302,
        status: "1",
        remark: "sdlkfjlksdfsd",
        id: "abc"
      },
      {
        coin: "BTC",
        amount: "0.00002552",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        txid:
          "c59bc457c8ec14ed8aa09a4c27915256c96e19e17eb0299677112665a2cc7768",
        ago: 1542858853,
        now: 1542860302,
        status: "1",
        remark: "sdlkfjlksdfsd",
        id: "abc"
      },
      {
        coin: "BTC",
        amount: "0.00002552",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        txid:
          "c59bc457c8ec14ed8aa09a4c27915256c96e19e17eb0299677112665a2cc7768",
        ago: 1542858853,
        now: 1542860302,
        status: "1",
        remark: "sdlkfjlksdfsd",
        id: "abc"
      }
    ],
    msg: "success"
  });
});

router.get("/selectAddress", function(
  req: Request,
  res: Response,
  next: NextFunction
) {
  res.json({
    code: 200,
    data: [
      {
        coin: "BTC",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        remark: "sdlkfjlksdfsd",
        id: "abc"
      },
      {
        coin: "BTC",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        remark: "sdlkfjlksdfsd",
        id: "abc"
      },
      {
        coin: "BTC",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        remark: "sdlkfjlksdfsd",
        id: "abc"
      }
    ],
    msg: "success"
  });
});

router.get(
  "/selectCoinConfig",
  async (req: Request, res: Response, next: NextFunction) => {
    res.json({
      code: 200,
      data: [
        {
          id: "82",
          coin: "BTC",
          depositAddress: "dslkfjdskljflksjlkfs"
        },
        {
          id: "81",
          coin: "TVC",
          depositAddress: "dslkfjdskljflksjlkfs"
        },
        {
          id: "80",
          coin: "ABBC",
          depositAddress: "dslkfjdskljflksjlkfs"
        }
      ],
      msg: "success"
    });
  }
);

router.get(
  "/coinAddress",
  async (req: Request, res: Response, next: NextFunction) => {
    const { coin } = req.query;
  }
);

router.get(
  "/selectDepositHistory",
  async (req: Request, res: Response, next: NextFunction) => {
    const { search } = req.query;
    const data = [
      {
        coin: "BTC",
        amount: "0.00002552",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        txid:
          "c59bc457c8ec14ed8aa09a4c27915256c96e19e17eb0299677112665a2cc7768",
        ago: 1542858853,
        now: 1542860302,
        status: "1",
        id: "abc"
      },
      {
        coin: "BTC",
        amount: "0.00002552",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        txid:
          "c59bc457c8ec14ed8aa09a4c27915256c96e19e17eb0299677112665a2cc7768",
        ago: 1542858853,
        now: 1542860302,
        status: "1",
        id: "abc"
      },
      {
        coin: "BTC",
        amount: "0.00002552",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        txid:
          "c59bc457c8ec14ed8aa09a4c27915256c96e19e17eb0299677112665a2cc7768",
        ago: 1542858853,
        now: 1542860302,
        status: "1",
        id: "abc"
      }
    ].filter(d => {
      return d.coin.toLowerCase().indexOf(search.toLowerCase()) > -1;
    });
    res.json({
      code: 200,
      data,
      msg: "success"
    });
  }
);

router.get(
  "/selectWithdrawHistory",
  async (req: Request, res: Response, next: NextFunction) => {
    const { search } = req.query;
    const data = [
      {
        coin: "BTC",
        amount: "0.00002552",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        txid:
          "c59bc457c8ec14ed8aa09a4c27915256c96e19e17eb0299677112665a2cc7768",
        ago: 1542858853,
        now: 1542860302,
        status: "1",
        id: "abc"
      },
      {
        coin: "BTC",
        amount: "0.00002552",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        txid:
          "c59bc457c8ec14ed8aa09a4c27915256c96e19e17eb0299677112665a2cc7768",
        ago: 1542858853,
        now: 1542860302,
        status: "1",
        id: "abc"
      },
      {
        coin: "BTC",
        amount: "0.00002552",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        txid:
          "c59bc457c8ec14ed8aa09a4c27915256c96e19e17eb0299677112665a2cc7768",
        ago: 1542858853,
        now: 1542860302,
        status: "1",
        id: "abc"
      }
    ].filter(d => {
      return d.coin.toLowerCase().indexOf(search.toLowerCase()) > -1;
    });
    res.json({
      code: 200,
      data,
      msg: "success"
    });
  }
);

router.get(
  "/selectWithdrawAddress",
  async (req: Request, res: Response, next: NextFunction) => {
    const data = [
      {
        coin: "BTC",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        remark: "sdlkfjlksdfsd",
        id: "abc"
      },
      {
        coin: "BTC",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        remark: "sdlkfjlksdfsd",
        id: "abc"
      },
      {
        coin: "BTC",
        address: "MHGtdHNwSaQzWaK2N7hxxGmELcZnuRK6fj",
        remark: "sdlkfjlksdfsd",
        id: "abc"
      }
    ];
    res.json({
      code: 200,
      data,
      msg: "success"
    });
  }
);

router.post(
  "/addAddress",
  async (req: Request, res: Response, next: NextFunction) => {
    const { coin, remark, address } = req.body;
    res.json({
      code: 200,
      data: undefined,
      msg: "success"
    });
  }
);

router.post(
  "/delAddress",
  async (req: Request, res: Response, next: NextFunction) => {
    const { id } = req.body;
    res.json({
      code: 200,
      data: undefined,
      msg: "success"
    });
  }
);

router.post(
  "/withdraw",
  async (req: Request, res: Response, next: NextFunction) => {
    const { amount, coin, address } = req.body;
    res.json({
      code: 200,
      data: undefined,
      msg: "success"
    });
  }
);

export default router;
